package org.support.small.mallms.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.support.small.infrastructure.mapper.BannersMapper;
import org.support.small.infrastructure.website.Banners;
import org.support.small.infrastructure.Tables;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Slf4j
@RestController
public class IndexController {
    @Resource
    private BannersMapper bannersMapper;

    @GetMapping("/a")
    public Object get(Page<Banners> page) {
        QueryWrapper queryWrapper = QueryWrapper.create().orderBy(Tables.BANNERS.CREATE_BY, false);
        bannersMapper.paginate(page, queryWrapper);
        return page;
    }

    @GetMapping("b")
    public Object b() {
        Banners banners = new Banners();
        banners.setTitle("ccc");
        banners.setUrl("url");
        banners.setSlug("/b");
        banners.setImage("image");
        bannersMapper.insert(banners);
        return "ok";
    }

    @GetMapping("c")
    public Object c() {
        bannersMapper.deleteById(33776041620000116L);
        return "ok";
    }

    @GetMapping("d")
    public Object d(Long bannerId) {
        Banners banners = new Banners();
        banners.setId(bannerId);
        banners.setImage(LocalDateTime.now().toString());
        bannersMapper.update(banners);
        return "ok";
    }
}
